/*
 * MainFrame.java
 *
 * Created on __DATE__, __TIME__
 */

package ui;

import com.live.spaces.shanboli.JxtaHelper;

import   org.w3c.dom.*;   

import foxtrot.Task;
import foxtrot.Worker;

/**
 * 
 * @author Tom Lee
 */
public class MainFrame extends javax.swing.JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JxtaHelper jh;

	protected boolean iniJXTAed = false;

	private String nickName;

	/** Creates new form MainFrame */
	public MainFrame() {
		initComponents();

	}

	private void iniJXTA() {
		jh = new JxtaHelper(peersTable,nickName );
		jh.startJxta();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
	private void initComponents() {
		jLabel1 = new javax.swing.JLabel();
		jScrollPane1 = new javax.swing.JScrollPane();
		peersTable = new javax.swing.JTable();
		jButton1 = new javax.swing.JButton();
		jTextField1 = new javax.swing.JTextField();
		jScrollPane2 = new javax.swing.JScrollPane();
		jTextArea1 = new javax.swing.JTextArea();
		jButton2 = new javax.swing.JButton();
		jToolBar1 = new javax.swing.JToolBar();
		startButton = new javax.swing.JButton();
		jMenuBar1 = new javax.swing.JMenuBar();
		jMenu1 = new javax.swing.JMenu();
		jMenu2 = new javax.swing.JMenu();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 18));
		jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		jLabel1.setText("JXChat2");
		jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

		peersTable.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] { { null, null }, { null, null },
						{ null, null }, { null, null } }, new String[] {
						"Nick Name", "IP" }));
		jScrollPane1.setViewportView(peersTable);

		jButton1.setText("Refresh");

		jTextArea1.setColumns(20);
		jTextArea1.setEditable(false);
		jTextArea1.setRows(5);
		jScrollPane2.setViewportView(jTextArea1);

		jButton2.setText("Send");

		startButton.setText("Start");
		startButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				handlerStartButton(evt);
			}
		});

		jToolBar1.add(startButton);

		jMenu1.setText("File");
		jMenuBar1.add(jMenu1);

		jMenu2.setText("Help");
		jMenuBar1.add(jMenu2);

		setJMenuBar(jMenuBar1);

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				org.jdesktop.layout.GroupLayout.LEADING).add(jLabel1,
				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 400,
				Short.MAX_VALUE).add(
				layout.createSequentialGroup().addContainerGap().add(
						jTextField1,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 312,
						Short.MAX_VALUE).addPreferredGap(
						org.jdesktop.layout.LayoutStyle.RELATED).add(jButton2)
						.add(15, 15, 15)).add(
				layout.createSequentialGroup().addContainerGap().add(
						jScrollPane2,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 375,
						Short.MAX_VALUE).add(15, 15, 15)).add(
				layout.createSequentialGroup().add(161, 161, 161).add(jButton1)
						.addContainerGap(164, Short.MAX_VALUE)).add(
				org.jdesktop.layout.GroupLayout.TRAILING,
				layout.createSequentialGroup().addContainerGap().add(
						jScrollPane1,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 375,
						Short.MAX_VALUE).add(15, 15, 15)).add(
				layout.createSequentialGroup().addContainerGap().add(jToolBar1,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 375,
						Short.MAX_VALUE).add(15, 15, 15)));
		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								layout
										.createSequentialGroup()
										.add(jLabel1)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												jToolBar1,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												25,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED,
												14, Short.MAX_VALUE)
										.add(
												jScrollPane1,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												88,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(jButton1)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												jScrollPane2,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.BASELINE)
														.add(jButton2)
														.add(
																jTextField1,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.addContainerGap()));
		pack();
	}// </editor-fold>//GEN-END:initComponents

	// GEN-FIRST:event_handlerStartButton
	private void handlerStartButton(java.awt.event.ActionEvent evt) {
		try {
			Worker.post(new Task() {
				public Object run() throws Exception {
					if (iniJXTAed == false) {
						iniJXTA();
						iniJXTAed = true;
					}
					return null;
				}
			});
		} catch (Exception ignored) {
		}

	}// GEN-LAST:event_handlerStartButton

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MainFrame().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton jButton1;

	private javax.swing.JButton jButton2;

	private javax.swing.JLabel jLabel1;

	private javax.swing.JMenu jMenu1;

	private javax.swing.JMenu jMenu2;

	private javax.swing.JMenuBar jMenuBar1;

	private javax.swing.JScrollPane jScrollPane1;

	private javax.swing.JScrollPane jScrollPane2;

	private javax.swing.JTextArea jTextArea1;

	private javax.swing.JTextField jTextField1;

	private javax.swing.JToolBar jToolBar1;

	private javax.swing.JTable peersTable;

	private javax.swing.JButton startButton;
	// End of variables declaration//GEN-END:variables

}